[SUBROUTINE]
version = 1.14
icon = drill-circle.png
name = _("Drill Circle")
type = drill_cir
help = _("<b>Drill a Regular Circle</b>")
order = act fcut h1 cx cy opt dim h4 num a ext center h3 s u_s ugc dpt u_dpt ugcd

[PARAM_ACT]
name = _("Active")
icon = enable.png
type = bool
value = 1

[PARAM_FCUT]
name = _("Show design")
icon = glasses.png
type = bool
value = 1

[PARAM_H1]
type = sub-header
name = _("Coords, size")

[PARAM_H4]
type = sub-header
name = _("Count, start, end")

[PARAM_H3]
type = sub-header
name = _("Drilling")

[PARAM_CX]
name = _("cX")
type = float
icon = center.png
tool_tip = _("Center of circle")
value = 0
metric_value = 0.0
header = h1

[PARAM_CY]
name = _("cY")
type = float
icon = center.png
tool_tip = _("Center of circle")
value = 0
metric_value = 0.0
header = h1

[PARAM_OPT]
name = _("Measure by")
type = combo
options = _("Diameter=1:Distance between holes=0")
icon = circ-arr-opt1.png
tool_tip = _("Select dimension option")
value = 1
header = h1

[PARAM_DIM]
name = _("Dimension")
type = float
minimum_value = 0.0
icon = line-len.png
tool_tip = _("Diameter or distance")
value = 2
metric_value = 50
header = h1
not_allowed = 0

[PARAM_NUM]
name = _("Number of holes")
type = int
minimum_value = 1
icon = copies-holes.png
tool_tip = _("Number of holes")
value = 5
header = h4

[PARAM_A]
name = _("Start")
type = float
digits = 2
icon = angle.png
tool_tip = _("Angle of the first hole")
value = 0
header = h4
suffix = &#176;

[PARAM_EXT]
name = _("Extend")
type = float
digits = 2
icon = ext-angle.png
tool_tip = _("Angle covered by holes")
value = 360
header = h4

[PARAM_CENTER]
name = _("Drill center")
type = bool
icon = drill-in-center.png
value = 0
tool_tip = _("Drill also at center")
header = h4

[PARAM_S]
name = _("Drill start")
type = combo
options = _("User defined=0:Surface=1:Half=2:One quarter=3:Three quarter=4:G-Code=5")
icon = drill-start.png
tool_tip = _("Pre or user defined")
value = 1
header = h3
links = u_s=0:ugc=5

[PARAM_U_S]
name = _("User start")
type = float
value = 0.0
metric_value = 0.0
header = h3
hidden = 1

[PARAM_UGC]
name = User gcode
type = gcode
value = 
header = h3
hidden = 1

[PARAM_UGCD]
name = User depth gcode
type = gcode
value =
header = h3
hidden = 1

[PARAM_DPT]
name = _("Drill down to")
type = combo-user
options = _("User defined=0:Through=1:Center drill depth=2:Bottom=3:Half=4:One quarter=5:Three quarter=6:G-Code=7")
icon = drill-end.png
tool_tip = _("Pre or user defined")
value = 1
header = h3
links = u_dpt=0:ugcd=7

[PARAM_U_DPT]
name = _("User depth")
type = float
value = -0.5
metric_value = -12.0
header = h3
hidden = 1

[DEFINITIONS]
content =
;	<eval>self.include_once(file name here)</eval>

[CALL]
content =
	(begin #sub_name)
	(drill a regular circle of #param_num holes author : Fernand Veilleux)
	
	o<#self_id_active> if [#param_act AND [#<_tool_usage> EQ 3]]
		o<select> CALL [31] [#param_s] [#param_u_s] [#<surface>] [#<surface> - #<wp_depth> / 2] [#<surface> - #<wp_depth> / 4] [#<bottom> + #<wp_depth> / 4] [#param_ugc]
		o<select> CALL [32] [#param_dpt] [#param_u_dpt] [#<bottom_through>] [#31 + #<center_drill_depth>] [#<bottom>] [#<surface> - #<wp_depth> / 2] [#<surface> - #<wp_depth> / 4] [#<bottom> + #<wp_depth> / 4] [#param_ugcd]
	
		#<d#ID> = [#param_dim]
		o<#self_id_10> if [#param_opt] ; option diameter
			#<radius#ID> = [#<d#ID> / 2]
		o<#self_id_10> else ; option distance between holes
			o<#self_id_10a> if [[#param_ext MOD 360] EQ 0]
				#<radius#ID> = [#<d#ID> / 2 / SIN[180 / #param_num]]
			o<#self_id_10a> else
				#<radius#ID> = [#<d#ID> / SIN[#param_ext / #param_num]]
			o<#self_id_10a> endif
		o<#self_id_10> endif
	
		o<#self_id_20> if [[[#param_ext MOD 360] NE 0] AND [#param_num GT 1]]
			#<fill#ID> = [#param_ext * #param_num / [#param_num - 1]]
		o<#self_id_20> else
			#<fill#ID> = #param_ext
		o<#self_id_20> endif
		
		o<set_spindle_rpm> CALL [#<_drill_rpm>] [#<_drill_feed>]
		
		o<#self_id_center> if [#param_center]
			o<drill_single> CALL [#param_cx] [#param_cy] [#31] [#32] [#<drill_diameter>] [#<drill_point_len>] [#param_fcut]
		o<#self_id_center> endif
	
		#<i#ID> = 0
		o<#self_id_loop> while [#<i#ID> LT #param_num]
			o<rotate_xy> CALL [#<radius#ID>] [0] [0] [0] [#param_a + [#<fill#ID> / #param_num] * #<i#ID>]
			o<drill_single> CALL [#param_cx + #<_rotated_x>] [#param_cy + #<_rotated_y>] [#31] [#32] [#<drill_diameter>] [#<drill_point_len>] [#param_fcut]
			#<i#ID> = [#<i#ID> + 1]
		o<#self_id_loop> endwhile
		
		o<#self_id_stop> if [#<_spindle_all_time> EQ 0]
			M9 M5
		o<#self_id_stop> endif
		
	o<#self_id_active> endif
	(end #sub_name)
